using UnityEngine;
using System.Collections;

/// <summary>
/// Tiene que estar en un GameObject con un collider con trigger.
/// </summary>
public class ObjectiveZone : MonoBehaviour 
{
    public string m_PlaceName = "Landing zone";
    public int m_PeopleNeeded = 2;
    public int m_QuestPriority = 0;
    private int m_PeopleInside = 0;

    private string m_ObjectiveID;

    Objective m_Objective;
	// Use this for initialization
	void Awake () 
    {
        m_ObjectiveID = "Reach " + m_PlaceName;

        m_Objective = QuestCreator.GetInstance().CreateObjective(m_QuestPriority, m_ObjectiveID, m_PeopleNeeded, "Llegar a la " + m_PlaceName, "");
	}
	
	// Update is called once per frame
	void Update () {
	
	}
    void OnTriggerEnter(Collider other)
    {
        //si entra un personaje
        if (other.GetComponent<Character>() != null)
        {
            m_PeopleInside++;
            QuestSystem.GetInstance().SendInfo(m_ObjectiveID, 1, "");
            if (m_Objective.IsCompleted())
            {
                this.gameObject.SetActive(false);
            }
        }
    }
    void OnTriggerExit(Collider other)
    {
        if (other.GetComponent<Character>() != null)
        {
            m_PeopleInside--;
            QuestSystem.GetInstance().SendInfo(m_ObjectiveID, -1, "");
        }
    }
}
